/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tree;

/**
 *
 * @author adam
 */
public class ArrayTree extends IdentifierTree{
    
    private VyrazTree point;
    IdentifierTree ident;    
    int dimension;
    private Type previous;
    private Type now;
    boolean right=false;
    
    public ArrayTree(Position start, Position end, VyrazTree point, String name,int dimension){
        super(start,end,name);
        this.point=point;
        this.dimension=dimension;
        
    }
    
    public void setRight(boolean b){
        this.right=b;
    }

    @Override
    public Type getType() {
        return Type.ARRAY;
    }
    
    @Override
    public String toString(){
        return String.format("ArrayTree %s: '%s'", super.toString(), point);
    }
    
     @Override
    public void accept(TreeVisitor visitor) {
        visitor.visitArrayTree(this);
    }
    
    @Override
    public void generate(Context ctx){
       point.generate(ctx);
       ctx.println("ldc "+dimension);
       if(right){
           ctx.println("aload "+getVariable().getSlot());
            if(now==Type.CONV){
            ctx.println("convert");
            now=previous;
        }
       }
    }

    /**
     * @return the point
     */
    public VyrazTree getPoint() {
        return point;
    }

    /**
     * @param point the point to set
     */
    public void setPoint(VyrazTree point) {
        this.point = point;
    }
    
      @Override
    public void setType(Type t) {
        previous=super.getVariable().getType();
        now=t;
        
    }
}
